<!DOCTYPE html>
<html>

	<head>
		<title>#(fileinfo.fileName??)</title>
		#include("common/head.html")
		<style type="text/css">
			#main-content {
				height: calc(100vh - 120px);
			}
		</style>
	</head>

	<body>
		<div class="am-cf admin-main" style="padding: 0;">
			<!-- sidebar start -->
			<!-- sidebar end -->
			<!-- content start -->
			<div class="admin-content">
				<div class="admin-content-body">
					<div class="am-cf am-padding">
						<div class="am-fl am-cf">
							<strong class="am-text-primary am-text-lg"><a>资源在线预览</a></strong> / <small>#(fileinfo.fileName ).#(fileinfo.fileExt )</small>
						</div>
					</div>
					<div class="am-u-sm-12">
						<div class="am-u-md-12 am-u-sm-12 am-u-lg-8">
							<div class="am-panel am-panel-default">
								<div class="am-panel-bd am-collapse am-in">
									<div id="main-content"></div>
								</div>
							</div>
							<!--
							<div class="am-panel am-panel-default">
								<div class="am-panel-hd">评论</div>
								<!-- 多说评论框 start --
								<div class="ds-thread" data-thread-key="#(fileinfo.fileId )" data-title="#(fileinfo.fileName )" data-url="lib/user/file/#(fileinfo.fileUuid )"></div>
								<!-- 多说评论框 end --
								<!-- 多说公共JS代码 start (一个网页只需插入一次) --
								<script type="text/javascript">
									var duoshuoQuery = {
										short_name: "soklib"
									};
									(function() {
										var ds = document.createElement('script');
										ds.type = 'text/javascript';
										ds.async = true;
										ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
										ds.charset = 'UTF-8';
										(document.getElementsByTagName('head')[0] ||
											document.getElementsByTagName('body')[0]).appendChild(ds);
									})();
								</script>
								<!-- 多说公共JS代码 end --
							</div>
							-->
						</div>

						<div class="am-u-md-12 am-u-sm-12 am-u-lg-4">
							<div class="am-panel am-panel-default">

								<div class="am-panel-hd am-cf" data-am-collapse="{target: '#collapse-panel-file-info1'}" title="#(fileinfo.fileName ).#(fileinfo.fileExt )">
									#(fileinfo.hiddenedFileName ).#(fileinfo.fileExt ) <span class="am-icon-chevron-down am-fr"></span>
								</div>
								<div class="am-panel-bd am-collapse am-in am-cf" id="collapse-panel-file-info1">

									<ul class="am-list admin-content-file">
										<li>
											<p>
												<span class="am-badge am-badge-secondary">上传用户</span> #(fileinfo.username)
											</p>

										</li>

										<li>
											<p>
												<span class="am-badge am-badge-secondary">大小</span> #(fileinfo.fileSizeFormat )
											</p>
										</li>

										<li>
											<p>
												<span class="am-badge am-badge am-badge-secondary">类别</span> #(fileinfo.categoryName )
											</p>
										</li>
										<li>
											<p>
												<span class="am-badge am-badge-secondary">上传时间</span>#(fileinfo.fileCreateTime )
											</p>
										</li>
										<li>
											<p>
												<span class="am-badge am-badge-secondary">简介</span> #(fileinfo.fileBrief )
											</p>

										</li>
										<li>
											<div class="am-btn-group am-btn-group-xs">
												<button type="button" id="fork" class="am-btn am-btn-default" onclick="findDoc()">
												<span class="am-icon-archive"></span> <span id="shoucang">收藏</span>
											</button>
												<a href="user/download/#(fileinfo.fileUuid)/#(fileinfo.fileExt)" type="button" class="am-btn am-btn-default"> <span class="am-icon-trash-o"></span> 下载
												</a>
											</div>

										</li>
									</ul>
								</div>

							</div>
							<div class="am-panel am-panel-default">
								<div class="am-panel-hd am-cf" data-am-collapse="{target: '#collapse-panel-link-file'}">
									关联文档<span class="am-icon-chevron-down am-fr"></span>
								</div>
								<div class="am-panel-bd am-collapse am-in am-cf" id="collapse-panel-link-file">
									<table class="am-table am-table-bdrs">
										<tbody id="relation-files">

										</tbody>
									</table>
								</div>
							</div>
						</div>
					</div>

				</div>
			</div>
		</div>
		<!-- 模态窗口 -->
		<div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-1">
			<div class="am-modal-dialog">
				<div class="am-modal-hd">
					收藏文件
					<a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
				</div>
				<div class="am-modal-bd">

					<div class="am-form">
						<div class="am-g am-margin-top-sm">

							<div class="am-u-sm-3   am-text-left ">名称:</div>
							<div class="am-u-sm-8 am-u-end">
								<input type="text" class="am-input-sm" value="#(fileinfo.fileName).#(fileinfo.fileExt )" readonly="readonly">
							</div>

							<div class="am-u-sm-3  am-text-left" style="margin-top: 10px;">文件夹:</div>
							<div class="am-u-sm-8 am-u-end" style="margin-top: 10px; margin-left: -10px;">
								<select id="select" data-am-selected="{searchBox: 1}">

								</select>
							</div>

							<div class="am-u-sm-3  am-text-left" style="margin-top: 10px; margin-bottom: 10px;">备注:</div>
							<div class="am-u-sm-8  am-u-end" style="margin-top: 10px; margin-bottom: 10px;">
								<textarea rows="2" id="forkNote" required="required" placeholder="文件备注"></textarea>
							</div>

							<div class="am-margin">
								<button type="button" onclick="submit()" class="am-btn am-btn-primary am-btn-xs" data-am-modal-close>提交保存</button>
								<button type="button" class="am-btn am-btn-primary am-btn-xs" data-am-modal-close>放弃保存</button>
							</div>
						</div>

					</div>

				</div>

			</div>
		</div>
		<div class="am-modal am-modal-loading am-modal-no-btn" tabindex="-1" id="my-modal-loading">
			<div class="am-modal-dialog">
				<div class="am-modal-hd">保存成功</div>
				<div class="am-modal-bd">
					<span class="am-icon-spinner am-icon-spin"></span>
				</div>
			</div>
		</div>
		<!-- content end -->
	</body>
	<script src="resource/script/pdfobject.min.js"></script>
	<script type="text/javascript" src="resource/ckplayer/ckplayer.js" charset="utf-8"></script>

	<script type="text/javascript">
		//操作收藏的js
		var forkId1 = 0;
		$(window).load(function() {
			fileId = #(fileinfo.fileId);
			$.ajax({
				url: "user/judgeFork",
				type: "POST",
				data: {
					fileId: fileId
				},
				datatype: "json",
				//ansyn : false,
				success: function(JsonResult) {
					/* var len=JsonResult.data.length;
					var docInfos=JsonResult.data; */
					if(JsonResult.success == false) {
						$("#shoucang").text("已收藏");
						$("#fork").addClass("am-active");
						forkId1 = JsonResult.data;
					} else {

						$("#fork").attr("data-am-modal", "{target: '#doc-modal-1', closeViaDimmer: 0, width: 400, height: 260}");
					}
				}
			})
		});

		function findDoc() {
			if($("#shoucang").text() == "已收藏") {
				$.ajax({
					url: "user/deleteFork",
					data: {
						forkId: forkId1
					},
					type: "POST",
					datatype: "json",
					//ansyn : false,
					success: function(JsonResult) {
						/* var len=JsonResult.data.length;
						var docInfos=JsonResult.data; */
						//alert("取消收藏");
						$("#fork").removeClass("am-active");
						$("#shoucang").text("收藏");
						$("#fork").attr("data-am-modal", "{target: '#doc-modal-1', closeViaDimmer: 0, width: 400, height: 260}");
					}
				})
			}
			$.ajax({
				url: "user/findAllByUserId",
				type: "get",
				datatype: "json",
				//ansyn : false,
				success: function(JsonResult) {
					var len = JsonResult.data.length;
					var docInfos = JsonResult.data;
					var innerStr = "";
					$('#select').empty();
					for(var i = 0; i < len; i++) {
						if(i == 0) {
							innerStr += "<option value='" + docInfos[i].docId +
								"' selected='selected'>" +
								docInfos[i].docName + "</option>"
						} else {
							innerStr += "<option value='" + docInfos[i].docId +
								"'>" +
								docInfos[i].docName + "</option>"
						}
					}
					$('#select').append(innerStr);
				}
			})
		}

		function submit() {
			docId = $("#select").val();
			docName = $("#select").text();
			forkNote = $("#forkNote").val();

			if(forkNote == null || forkNote == "") {
				forkNote = "无";
			}
			fileId = #(fileinfo.fileId);
			$.ajax({
				url: "user/insertFork",
				data: {
					docId: docId,
					forkNote: forkNote,
					fileId: fileId
				},
				type: "POST",
				datatype: "json",
				//ansyn : false,
				success: function(JsonResult) {
					/* var len=JsonResult.data.length;
					var docInfos=JsonResult.data; */
					//alert(JsonResult.error);
					$("#shoucang").text("已收藏");
					$("#fork").addClass("am-active");
					$("#fork").removeAttr("data-am-modal");
					forkId1 = JsonResult.data;
				}
			})

		}

		var mainFileId = #(fileinfo.fileId);
		//关联文档的获取
		function getRelation() {
			$("#relation-files").hide();

			$.post("user/get-relations/" + mainFileId, function(data) {
				var str = "";
				for(var i = 0; i < data.data.length; i++) {
					str += "<tr><td><a target='_blank' title='点击预览' href='user/file/" + data.data[i].relationFile.fileUuid + "'><img src='user/thumbnail/" +
						data.data[i].relationFile.fileUuid + "/png' width='30' height='30' alt='...' class='am-img-thumbnail am-radius'>  " +
						data.data[i].relationFile.fileName + "." + data.data[i].relationFile.fileExt + "</a></td>" +
						"</tr>";
				}

				$("#relation-files").html(str);
				if(data.data.length == 0) {
					$("#relation-files").html("无关联文档...");
				}
				$("#relation-files").show("fast");

			})
		}
		//执行获取关联文档
		getRelation();
		//------------------------
		var ext = "#(fileinfo.fileExt)";
		var uuid = "#(fileinfo.fileUuid)";
		//判断是哪种浏览方式在网页中呈现
		//页面显示js
		var host = location.host; // 192.168.1.104
		host = host.substring(0, host.indexOf(':'));
		var fileUrl = "user/thumbnail/" + "#(fileinfo.fileUuid)" + "-";
		var readUrl = "user/thumbnail/" + "#(fileinfo.fileUuid)" + "-" + "#(fileinfo.fileExt)";
		var $content = $("#main-content");
	</script>
	<script src="resource/script/file-view.js"></script>

</html>